#AM_CPPFLAGS =								\
#	-I$(top_builddir)						\
#	-I$(top_srcdir)							\
#	-I$(top_srcdir)/libxfsm                                         \
#	-DG_LOG_DOMAIN=\"xfce4-session\"				\
#	-DLIBDIR=\"$(libdir)\"						\
#	-DPACKAGE_LOCALE_DIR=\"$(localedir)\"				\
#	-DSYSCONFDIR=\"$(sysconfdir)\"					\
#	$(PLATFORM_CPPFLAGS)
#

find_program(ICEAUTH_CMD iceauth)

add_custom_command(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xfsm-chooser-icon.h
    COMMAND gdk-pixbuf-csource
            --static --raw
            --name=xfsm_chooser_icon_data
            ${CMAKE_CURRENT_SOURCE_DIR}/xfsm-chooser-icon.png
            > ${CMAKE_CURRENT_BINARY_DIR}/xfsm-chooser-icon.h
    COMMENT "Embedding xfsm-chooser-icon.png into C source file"
)

execute_process(COMMAND glib-genmarshal
                        --prefix=xfsm_marshal --internal --header
                        ${CMAKE_CURRENT_SOURCE_DIR}/xfsm-marshal.list
                        --output ${CMAKE_CURRENT_BINARY_DIR}/xfsm-marshal.h
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
execute_process(COMMAND glib-genmarshal
                        --prefix=xfsm_marshal --body
                        ${CMAKE_CURRENT_SOURCE_DIR}/xfsm-marshal.list
                        --output ${CMAKE_CURRENT_BINARY_DIR}/xfsm-marshal.c
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
execute_process(COMMAND gdbus-codegen
        --c-namespace=XfsmDbus
        --interface-prefix=org.vvxfce.Session.
        --generate-c-code=xfsm-client-dbus
        ${CMAKE_CURRENT_SOURCE_DIR}/xfsm-client-dbus.xml
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
execute_process(COMMAND gdbus-codegen
        --c-namespace=XfsmDbus
        --interface-prefix=org.vvxfce.Session.
        --generate-c-code=xfsm-manager-dbus
        ${CMAKE_CURRENT_SOURCE_DIR}/xfsm-manager-dbus.xml
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

set(SOURCES
        ${CMAKE_CURRENT_BINARY_DIR}/xfsm-chooser-icon.h
        ${CMAKE_CURRENT_BINARY_DIR}/xfsm-client-dbus.c
        ${CMAKE_CURRENT_BINARY_DIR}/xfsm-client-dbus.h
        ${CMAKE_CURRENT_BINARY_DIR}/xfsm-manager-dbus.c
        ${CMAKE_CURRENT_BINARY_DIR}/xfsm-manager-dbus.h
        ${CMAKE_CURRENT_BINARY_DIR}/xfsm-marshal.c
        ${CMAKE_CURRENT_BINARY_DIR}/xfsm-marshal.h
        ice-layer.c
        ice-layer.h
        main.c
        sm-layer.c
        sm-layer.h
        xfsm-chooser.c
        xfsm-chooser.h
        xfsm-client.c
        xfsm-client.h
        xfsm-client-dbus.h
        xfsm-compat-gnome.c
        xfsm-compat-gnome.h
        xfsm-compat-kde.c
        xfsm-compat-kde.h
        xfsm-consolekit.c
        xfsm-consolekit.h
        xfsm-dns.c
        xfsm-dns.h
        xfsm-error.c
        xfsm-error.h
        xfsm-fadeout.c
        xfsm-fadeout.h
        xfsm-global.c
        xfsm-global.h
        xfsm-legacy.c
        xfsm-legacy.h
        xfsm-logout-dialog.c
        xfsm-logout-dialog.h
        xfsm-manager.c
        xfsm-manager.h
        xfsm-properties.c
        xfsm-properties.h
        xfsm-shutdown-fallback.c
        xfsm-shutdown-fallback.h
        xfsm-shutdown.c
        xfsm-shutdown.h
        xfsm-startup.c
        xfsm-startup.h
        xfsm-systemd.c
        xfsm-systemd.h
)

add_executable(${PROJECT_NAME}
        ${SOURCES}
)

set(deps)
if (${IS_ALONE_COMPILE})
	list(APPEND deps PkgConfig::XFCE4_UI)
        list(APPEND deps PkgConfig::GMODULE)
        list(APPEND deps PkgConfig::GIO)
        list(APPEND deps PkgConfig::WNCK)
        list(APPEND deps PkgConfig::XFCONF)
else()
	list(APPEND deps libxfce4ui-2)
	list(APPEND deps glib-shared)
	list(APPEND deps libwnck3-shared)
	list(APPEND deps vvxfconf-0)
endif()

target_link_libraries(${PROJECT_NAME}
        PRIVATE
        vvxfce4-session-macros-interface
        libxfsm
        PkgConfig::X11
        PkgConfig::POLKIT_GOBJECT
        PkgConfig::SM
        PkgConfig::ICE
	${deps}
        -lm
)

install(TARGETS ${PROJECT_NAME}
        DESTINATION bin
)

#
#if HAVE_POLKIT
#
#@INTLTOOL_POLICY_RULE@
#
#polkit_policydir = $(datadir)/polkit-1/actions
#polkit_policy_DATA =					\
#	org.xfce.session.policy
#
#%.policy.in: %.policy.in.in
#	sed "s|[@]HELPER_PATH_PREFIX@|${HELPER_PATH_PREFIX}|" $< > $@
#
#endif
set(_HELPER_PATH_PREFIX_ ${CMAKE_INSTALL_PREFIX}/${HELPER_PATH_PREFIX})
configure_file(
        ${CMAKE_CURRENT_SOURCE_DIR}/org.vvxfce.session.policy.in
        ${CMAKE_CURRENT_BINARY_DIR}/org.vvxfce.session.policy
        @ONLY
)

install(FILES
        ${CMAKE_CURRENT_BINARY_DIR}/org.vvxfce.session.policy
        DESTINATION /usr/share/polkit-1/actions
)
